#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include<stack>
#include<vector>
using namespace std;


class Solution {
public:
    bool IsPopOrder(vector<int>& pushV, vector<int>& popV)
    {
        stack<int> st;
        int pushi = 0;
        int popi = 0;
        while (pushi != pushV.size())
        {
            st.push(pushV[pushi++]);

            while (!st.empty() && st.top() == popV[popi])
            {
                st.pop();
                ++popi;
            }
        }

        return st.empty();
    }
};

int main()
{
    vector<int> v1 = { 1, 2, 3, 4, 5 };
    vector<int> v2 = { 4, 5, 3, 2, 1 };
    cout << Solution().IsPopOrder(v1, v2) << endl;

    return 0;
}